package com.bootdo.blog.controller;

import com.bootdo.common.annotation.Log;
import com.bootdo.common.utils.IPUtils;
import com.bootdo.common.utils.R;
import com.bootdo.common.utils.WeRedPackUtils;
import com.bootdo.system.domain.BpostionDO;
import com.bootdo.system.service.BpostionService;
import com.jfinal.weixin.sdk.api.ApiConfig;
import com.jfinal.weixin.sdk.api.ApiConfigKit;
import com.jfinal.weixin.sdk.jfinal.ApiController;
import groovy.util.logging.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.UUID;
import java.util.logging.Logger;


/**
 * 
 * 
 * @author chgleeØ
 * @email 1992lcg@163.com
 * @date 2018-03-18 19:36:43
 */
 
@Controller
@RequestMapping("/bpostion/api")
@Slf4j("BpostionApiController")
public class BpostionApiController extends ApiController {
	@Autowired
	private BpostionService bpostionService;




	//场景id
	String scene_id="PRODUCT_5";


	//红包金额单位分
	String total_amount="50";
	//红包发放总人数
	String total_num="1";

	String wishing="感谢，你自首或举荐的勇气，小小心意，不曾敬意!";
	String act_name="推荐有奖";
	String remark="谢谢关注";

	private static String partner="1498618492";
	String wxappid="wx24dffff92fcc6bad";
	//商户名称
	String paternerKey="dd19890387d1beb557ff9322c22d6b1f";
	//商户名称
	String sendName="金立";
	String certPath="/Users/guchenglin/Desktop/cert/apiclient_cert.p12";

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(@RequestBody BpostionDO bpostion, HttpServletRequest httpServletRequest){

		if(bpostionService.save(bpostion)>0){
//			try {
//				String send = WeRedPackUtils.send(UUID.randomUUID().toString(), scene_id, IPUtils.getIpAddr(httpServletRequest),
//						total_amount,
//						total_num,
//						wishing,
//						act_name,
//						remark,
//						bpostion.getOpenApi(),
//						partner,
//						wxappid,
//						sendName,
//						paternerKey,
//						certPath);
//
//			}catch (Exception e){
//				e.printStackTrace();
//			}


			return R.ok();
		}
		return R.error();
	}





	@Override
	public ApiConfig getApiConfig() {
		ApiConfig apiConfig =new ApiConfig();
		apiConfig.setAppId("wx24dffff92fcc6bad");
		apiConfig.setAppSecret("dd19890387d1beb557ff9322c22d6b1f");
		apiConfig.setToken("verify_token");
		apiConfig.setEncodingAesKey("ozMYIVWlRF6IQKtlnDiSWoJt0LM6OqahlQpbEqCo2kO");
		ApiConfigKit.setThreadLocalApiConfig(apiConfig);
		return ApiConfigKit.getApiConfig();
	}
}
